﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Kangaroo.Model;

namespace Kangaroo.Controls.ChannelView
{
    public class EquipFirstChannelView : BaseChannelView
    {
        protected override TreeNode[] StartPrepareTreeNodes(ChannelInfo[] channels)
        {
            return GroupByEquipId(channels);
        }

        protected override TreeNode DoGetEquipPhaseNode(IGrouping<EquipPhase, ChannelInfo> groupingByEquipPhase)
        {
            // 设备相位
            var equipPhase = groupingByEquipPhase.Key;
            return HideRedundantNodes && groupingByEquipPhase.Count() == 1 ?
                new TreeNode(equipPhase.ToString()) { Tag = groupingByEquipPhase.Single() } :
                new TreeNode(equipPhase.ToString(), GroupByDevId(groupingByEquipPhase));
        }

        protected override TreeNode GetDevChnNode(IGrouping<short, ChannelInfo> groupingByDevChn)
        {
            // 装置通道
            var devChn = groupingByDevChn.Key.ToString();
            return new TreeNode(devChn) { Tag = groupingByDevChn.Single() };
        }
    }
}